<?php
/*
 * @Author: 杨红兵
 * @Last Modified by: 杨红兵
 * @Last Modified time: 2022-07-27 17:40:06
 */

namespace app\libraries\utils\wechat;

use EasyWeChat\Kernel\Contracts\AccessTokenInterface;
use EasyWeChat\OfficialAccount\Auth\AccessToken as AuthAccessToken;

class AccessToken extends AuthAccessToken
{
    /**
     * @param string $token
     * @param int    $lifetime
     *
     * @return \EasyWeChat\Kernel\Contracts\AccessTokenInterface
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
     * @throws \Psr\SimpleCache\InvalidArgumentException
     */
    public function setToken(string $token, int $lifetime = 7200): AccessTokenInterface
    {
        if ($lifetime > 600) {
            $lifetime -= 300;
        }
        return parent::setToken($token, $lifetime);
    }
}
